"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
function RangeValidate(min, max) {
    return function (target, propertyKey, descriptor) {
        // 保存原始的 setter
        const originalSetter = descriptor.set;
        // 重写 setter
        descriptor.set = function (value) {
            // 检查设置的值是否在指定的最小值和最大值之间
            if (value < min || value > max) {
                // 如果值不在范围内, 抛出错误
                throw new Error(`${propertyKey} 的值应该在 ${min} 到 ${max} 之间！`);
            }
            // 如果值在范围内，且原始 setter 方法存在，则调用原始 setter 方法
            if (originalSetter) {
                originalSetter.call(this, value);
                // originalSetter.apply(this, value)
            }
        };
    };
}
class Weather {
    constructor(_temp) {
        this._temp = _temp;
    }
    // 设置温度范围在 -50 到 50 之间
    set temp(value) {
        this._temp = value;
    }
    get temp() {
        return this._temp;
    }
}
__decorate([
    RangeValidate(-50, 50)
], Weather.prototype, "temp", null);
const w1 = new Weather(28);
console.log(w1.temp);
w1.temp = 9000; // Uncaught Error: temp 的值应该在 -50 到 50 之间！
console.log(w1.temp);
